package com.example.emqxclient.controller;

import com.alibaba.nacos.api.NacosFactory;
import com.example.emqxclient.client.EmqClient;
import com.example.emqxclient.entity.ApiResponse;
import com.example.emqxclient.properties.QosEnum;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
//import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

//发推送
@RestController
@Slf4j
//@FeignClient(name = "publish-feign")
public class PublishController {
    @Resource
    private EmqClient emqClient;

    //    http://localhost:9001/publish?topic=testtopic/A&message=message
    // 发送消息接口
    @RequestMapping("/publish")
    public ApiResponse<String> sendMessage(@RequestParam String topic,
                                           @RequestParam String message) {
        log.info("Sending message to topic: {}, message: {}", topic, message);
        emqClient.publish(topic, message, QosEnum.QoS2, false);
        return ApiResponse.success("Message sent successfully to " + topic);
    }
}
